#include <iostream>

class T
{
public:
	T() : m(0) { }
	T(int x): m(x) { }

	T& operator=(const T &x) &
	{
		std::cout << __LINE__ << " lvaule reference" << std::endl;
		m = x.m;
		return *this;
	}
	
	T& operator=(const T &x) &&
	{
		std::cout << __LINE__ << " rvalue reference" << std::endl;
		m = x.m;
		return *this;
	}

	T& operator+(const T &x) &
	{
		std::cout << __LINE__ << " operator+" <<  std::endl;
		m += x.m;
		return *this;
	}

	T& operator+(const T &x) &&
	{
		std::cout << __LINE__ << " operator+" << std::endl;
		m += x.m;
		return *this;
	}

	friend std::ostream& operator<<(std::ostream &os, const T &x)
	{
		os << x.m;
		return os;
	}
private:
	int m;
};

int main()
{
    T x(1), y(2);

	x + y = T(3);

	std::cout << (T(4) = x + y) << std::endl;

	std::cout << x << std::endl;
}

